<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core">

<p:panel header="PROJETOS" style="width:1500px">
	<h:form id="formProjeto">
		<p:growl id="growl" showDetail="true" life="3000" />
		<h:panelGrid columns="9" cellpadding="5">
                Nome:
                <p:inputText size="30" value="#{projetoBean.nome}" />
                Categoria:
                <p:selectOneMenu id="categoria"
				value="#{projetoBean.categoria}" converter="categoriaConverter">
				<f:selectItem itemLabel="-- Selecione --" />
				<f:selectItems value="#{categoriaBean.categorias}" var="categoria"
					itemValue="#{categoria}" itemLabel="#{categoria.nome}" />

			</p:selectOneMenu> 
                Ano:
                <p:selectOneMenu id="ano" value="#{projetoBean.ano}">
				<f:selectItem itemLabel="-- Selecione --" />
				<f:selectItems value="#{projetoBean.anos}" var="ano"
					itemValue="#{ano}" itemLabel="#{ano}" />

			</p:selectOneMenu>
			<h:outputText rendered="${usuarioSessaoBean.perfil == 'DP'}"
				value="Em aberto" />

			<p:selectBooleanCheckbox
				rendered="${usuarioSessaoBean.perfil == 'DP'}"
				value="#{projetoBean.emAberto}" />

			<p:commandButton value="Pesquisar" update="@form"
				action="#{projetoBean.pesquisar}" />
		</h:panelGrid>
		<br />
		<br />
		<p:dataTable id="gridProjetos" var="projeto"
			value="#{projetoBean.projetos}"
			emptyMessage="Nenhum registro encontrado" paginator="true" rows="10"
			paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
			rowKey="#{projeto.id}" selection="#{projetoBean.projConsultado}"
			selectionMode="single" paginatorPosition="top">
			<p:ajax event="rowSelect" update="botoes" />
			<p:column headerText="Projeto">
				<h:outputText value="#{projeto.nome}" />
			</p:column>
			<p:column headerText="Valor">
				<h:outputText value="#{projeto.valor}">
					<f:convertNumber currencySymbol="R$" type="currency" />
				</h:outputText>
			</p:column>
			<p:column headerText="Categoria">
				<h:outputText value="#{projeto.categoria}" />
			</p:column>

			<p:column headerText="Status">
				<h:outputText value="#{projeto.status}" />
			</p:column>

			<p:column headerText="Lances">
				<h:outputText value="#{projeto.nrLances}" />

			</p:column>

			<f:facet name="footer">
				<h:panelGroup id="botoes">
					<h:panelGroup rendered="${usuarioSessaoBean.perfil == 'DP'}">
						<p:button id="btCadastrar" icon="ui-icon-search"
							value="Novo Projeto" outcome="/projeto/cadastrarProjeto">

						</p:button>
						<p:button id="btVisualizar"
							rendered="#{projetoBean.projConsultado != null}"
							icon="ui-icon-search" value="Visualizar"
							outcome="/projeto/consultarProjeto">
							<f:param name="projeto" value="#{projetoBean.projConsultado.id}" />
						</p:button>
						<p:button id="btLances"
							rendered="${projetoBean.projConsultado.nrLances != 0}"
							value="Lances" outcome="/lance/exibirLances">
							<f:param name="projeto" value="#{projetoBean.projConsultado.id}" />
						</p:button>

						<p:commandButton ajax="false" value="Emitir Relatorio"
							action="#{projetoBean.emitirRelatorio()}"  target="_blank"/>





					</h:panelGroup>

					<h:panelGroup rendered="${usuarioSessaoBean.perfil == 'FREE'}">
						<p:button id="btVisualizar1"
							rendered="#{projetoBean.projConsultado != null}"
							icon="ui-icon-search" value="Visualizar"
							outcome="/projeto/consultarProjeto">
							<f:param name="projeto" value="#{projetoBean.projConsultado.id}" />
						</p:button>

						<!-- Panel de Botoes do Freelancer -->

						<p:commandButton id="btEfetuarLances" process="@form" ajax="false"
							value="Efetuar Lance" action="#{lanceBean.efetuarLance()}">
							<f:setPropertyActionListener
								value="#{projetoBean.projConsultado}"
								target="#{lanceBean.projeto}" />
							<f:setPropertyActionListener value="#{usuarioSessaoBean.usuario}"
								target="#{lanceBean.usuarioSessao}" />
						</p:commandButton>

					</h:panelGroup>

					<h:panelGroup rendered="${usuarioSessaoBean.perfil == null}">
						<p:button id="btVisualizar2"
							rendered="#{projetoBean.projConsultado != null}"
							icon="ui-icon-search" value="Visualizar"
							outcome="/projeto/consultarProjeto">
							<f:param name="projeto" value="#{projetoBean.projConsultado.id}" />
						</p:button>

						<p:button id="btVoltar" value="Voltar"
							outcome="/login/efetuarLogin">

						</p:button>



					</h:panelGroup>

				</h:panelGroup>
			</f:facet>

		</p:dataTable>
	</h:form>
</p:panel>


</html>

